package com.webshop.service;

import com.webshop.DataDao.AddShopcarDao;
import com.webshop.JavaBean.Goods;
import com.webshop.JavaBean.Shopcar;

import java.util.ArrayList;
import java.util.List;

  public class ShopcarService {
      UltimateServie us = new UltimateServie();
        AddShopcarDao addShopcarDao=new AddShopcarDao();
        //加入购物车
        public void insertservice(Shopcar s){
            try {
                addShopcarDao.insert(s);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
      //修改数量
    public void modifyService(Shopcar shopcar)throws Exception{
            addShopcarDao.modify(shopcar);
    }

    /**
     * 想购物车页面返回商品
     * @param shopcar
     * @return
     * @throws Exception
     */
    public  Shopcar findService(Shopcar shopcar)throws Exception{
            Shopcar shopcar1=new Shopcar();
            shopcar1 =addShopcarDao.find(shopcar);
            Goods t = us.backGood(shopcar1.getGoodsAttrID());//根据商品属性id返回主商品。

            return shopcar1;
    }

      /**
       * 根据商品属性的id，返回详细的购物车
       * @param ID
       * @param name
       * @return
       */
      public Shopcar backShopcarDenpendAttrID(String ID, String name) {
          return addShopcarDao.backShopCarDependAttrID(ID, name);
      }


      /**
       * 根据ID返回单一的购物车
       * @param ID
       * @return
       */
      public Shopcar backShopCar(String ID) {
          return addShopcarDao.backShopCar(ID);
      }


    /**
     * 返回我购买的所有物品
     * @param name
     * @return
     * @throws Exception
     */
    public List<Shopcar> buyfindshop(String name){
            List<Shopcar> shopcars=new ArrayList<>();
        try {
            shopcars=addShopcarDao.buyfind(name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return shopcars;
    }
    //删除购物车的物品
    public void delete(int ID)throws Exception{
        addShopcarDao.deleter(ID);
    }
}
